# -*- coding: utf-8 -*-
"""
Created on 2021/5/31 18:09

@File: append_this_station_into_organization.py
@Author: LT
@Description: 去到EnOS的组织结构将之前新建的场站添加到组织结构中，然后post对应的api就行
              ！！不过，这个简单的页面它却用了复杂的二进制form-data来搞，麻烦死了
"""
from requests import post


class AppendStationIntoOrganization:
    def __init__(self, *siteids, parentid='1859febe5ce70000'):
        """parentid是固定的，指的是联元！siteids可以批量变成列表来添加进组织结构"""
        self.link = 'https://portal-lywz1.eniot.io/configuration/rest/org/attachsite'
        self.data = {
            "siteids": str(list(siteids)).replace('\'', '\"'),
            "parentid": parentid
        }
        self.res = self.__request()

    def __request(self):
        res = post(url=self.link, params=self.data)
        res.close()
        return res


if __name__ == '__main__':
    exp = AppendStationIntoOrganization(*['26dc12ff45806000', '26dc130266002000'])
    print(exp.res.json())
    # 返回体是：{
    # 'retCode': 10000,
    # 'errMsg': '',
    # 'data': True
    # }
